<?php

namespace V6;
class  CaptchaCode extends \ResourceClass
{

    public $isActive = true;
    public $remark = '获取图片识别码';

    public function get(array $req, array $post, &$result)
    {
        try{
            if (!isset($req['regid'])) {
                return 'require user regid';
            }
            $captcha_code_key = $req['regid'];
            $picture_code = new \CaptchaCode();		//实例化一个对象
            $image_data_base64 = $picture_code->doimg();
             //连接 memcache
            $memcache = new \Memcache();
            $con = $memcache->connect(\Util\Config::get('memcache_host', 'Memcache'), \Util\Config::get('memcache_port', 'Memcache'));
            if (!$con) {
                return 0;
            }
            //添加缓存
            $memcache->set('CAPTCHA_CODE_'.$captcha_code_key,$picture_code->getCode(),MEMCACHE_COMPRESSED,900);
            $result['captcha_code_base64'] = $image_data_base64;
        }catch (\Exception $e){
            echo $e->getMessage();
        }
    }
}